package com.yuan.member.controller;

import cn.common.constant.BalanceConstant;
import cn.common.result.Response;
import cn.common.utils.UserContextUtils;
import cn.model.Balance;
import com.yuan.member.service.BalanceService;
import com.yuan.security.annotation.RequiresLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/balance")
public class BalanceController {
    @Autowired
    private BalanceService balanceService;
    @RequiresLogin
    @GetMapping("/list")
    public Response list() {
//        try {
//            Class.forName("io.netty.channel.EventLoopGroup");
//            System.out.println("Netty is available!");
//        } catch (ClassNotFoundException e) {
//            System.out.println("Netty is NOT available!");
//        }
        String userId = UserContextUtils.getCurrentUserId();
        List<Balance> balanceList = balanceService.list(userId);
        return Response.Success(balanceList);
    }
    @RequiresLogin
    @PostMapping(value = "/transferBalances")
    public Response transferBalances(@RequestParam String currency,@RequestParam BigDecimal balance,@RequestParam BalanceConstant.Move_Type move_type) {

        return Response.Success(balanceService.transferBalances(currency,balance,move_type));
    }
    @RequiresLogin
    @GetMapping("/getBalances")
    public Response getBalances(String currency) {
        return Response.Success(balanceService.getBalances(currency));
    }

}
